package com.beemans.corekit.ui.activity;

import android.os.Bundle;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.viewbinding.ViewBinding;

import com.beemans.corekit.constant.AppConstant;
import com.beemans.corekit.constant.ReportEventConstants;
import com.beemans.corekit.data.RemotePushEntity;
import com.beemans.corekit.integration.toolkit.ActivityUtils;
import com.beemans.corekit.utils.ReportUtils;

public class NotificationActivity extends BaseActivity<ViewBinding> {
    @Nullable
    private RemotePushEntity remotePushEntity;

    @Nullable
    @Override
    protected ViewBinding getViewBinding() {
        return null;
    }

    @Override
    protected void initData(@Nullable Bundle bundle) {
        if (bundle != null) {
            final Object object = bundle.get(AppConstant.REMOTE_PUSH_ENTITY);
            if (object instanceof RemotePushEntity) {
                remotePushEntity = (RemotePushEntity) object;
            }

            Log.e("susu", "NotificationActivity --- remotePushEntity:" + remotePushEntity);
        }

        if (remotePushEntity != null) {
            ReportUtils.reportRemotePushEvent(ReportEventConstants.REMOTE_PUSH_CLICK, remotePushEntity);
        }
    }

    @Override
    protected void initViews() {
    }

    @Override
    public void loadData() {
        handleLocalPushNotification();
    }

    private void handleLocalPushNotification() {
        final boolean hasOtherAct = ActivityUtils.getActivityList()
                .stream()
                .anyMatch(activity -> !(activity instanceof NotificationActivity));

        if (hasOtherAct) {
            ActivityUtils.finishActivity(this, false);
            return;
        }

        ActivityUtils.startActivity(MainActivity.class);
        ActivityUtils.finishActivity(this, false);
    }
}